﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace UYD_WCS_AS_AGV_Controller.BaseClass
{
    public static class CTaskInfo
    {

        /// <summary>
        /// 任务明细获取时间延时
        /// </summary>
        public static int TaskGetDelay=10;
        ///// <summary>
        ///// 当前是否有任务
        ///// </summary>
        //public static bool IsHasTask;

        /// <summary>
        /// 当前任务信息
        /// </summary>
        //public static UYD_WCS.Model.W_TASK_AGV CurrentTask;

        public static AGV.Model.WCS_AGV_TASK CurrentTask=new AGV.Model.WCS_AGV_TASK();
        /// <summary>
        /// AGV接口调用地址
        /// </summary>
        public static string AGV_URL;

        /// <summary>
        /// WCS接口调用地址
        /// </summary>
        public static string WCS_URL;
        /// <summary>
        /// WCS串口发送数据列表
        /// </summary>
        public static List<byte[]> WcsComSendDataList = new List<byte[]>();

        /// <summary>
        /// 添加WCS串口发送数据
        /// </summary>
        /// <param name="addrCode">地址码</param>
        /// <param name="funcCode">功能码</param>
        /// <param name="sendData">值</param>
        public static void AddToWcsSendDataList(byte addrCode, byte funcCode, byte sendData)
        {
            bool blExist = false;
            for (int i = 0; i < CTaskInfo.WcsComSendDataList.Count; i++)
            {

                byte[] bTemp = CTaskInfo.WcsComSendDataList[i];

                if (bTemp[0] == 0x7E && bTemp[1] == addrCode && bTemp[2] == funcCode)
                {
                    blExist = true;
                    break;
                }
            }
            if (blExist) return;

            byte[] b = new byte[] { 0x7E, addrCode, funcCode, 0x01, sendData };
            int sum = 0;
            for (int i = 0; i < b.Length; i++)
            {
                sum += b[i];
            }
            //sum = sum % 256;
            //sum = ~sum + 1;

            byte[] bSend = new byte[] { 0x7E, addrCode, funcCode, 0x01, sendData, (byte)sum, 0x68 };
            CTaskInfo.WcsComSendDataList.Add(bSend);
        }


        public static List<Smart200Data> PLCSRMReadDataList = new List<Smart200Data>();
        public static List<Smart200Data> PLCSRMWirteDataList = new List<Smart200Data>();

        public static List<SRMTaskSend> PLCSRMTaskSendList = new List<SRMTaskSend>();
        public static List<AGVTaskSend> AGVTaskSendList = new List<AGVTaskSend>();


        public static bool CheckForkStatus_Before_Move_Get_SendedToPlc = false;
        public static bool CheckForkStatus_Before_Get_SendedToPlc = false;
        public static bool CheckForkStatus_Before_Move_Set_SendedToPlc = false;
        public static bool CheckForkStatus_Before_Set_SendedToPlc = false;


        public static bool CheckForkStatus_Get_Finished_SendedToAgv = false;
        public static bool CheckForkStatus_Set_Finished_SendedToAgv = false;

        public static bool Check_MoveToGetLoc_SendedToAgv = false;



        public static bool AgvIsHasAlarm = false;
        public static string AgvAlarmInfo = "";


        public static string AgvGetSetPointLoc = "L0200";
        public static string Agv_GetSetPointX = "3.125";
        public static string Agv_GetSetPointY = "4.123"; 
        public static string AgvCurrentLoc = "";
        public static string WareName = "";
        public static string AgvAutoChangeLowValue = "15";
        public static string AgvChargingLoc = "LM70";
        public static List<string> SetGoodAppltLoc = new List<string>();
    }
    


    public class Smart200Data
    {
        /// <summary>
        /// 读取的数据地址
        /// </summary>
        public string addr="";
        /// <summary>
        /// 0:read 1:write 
        /// </summary>
        public short read=0;
        /// <summary>
        /// 0:bool 1:short 2:int 3:boolArray 4:shortArray 5:byte
        /// </summary>
        public short valtype=0;
        /// <summary>
        /// 读取写入值,读取时默认为0
        /// </summary>
        public object val;
        /// <summary>
        /// 读取的数据个数
        /// </summary>
        public ushort arraylen = 0;
    }

    public class SRMTaskSend
    {
        public string taskCode { get; set; }
        public short taskType { get; set; }
        public ushort taskId { get; set; }
        public short taskGroup { get; set; }
        public short taskColl { get; set; }
        public short taskFloor { get; set; }
    }

    public class AGVTaskSend
    {
        public string taskCode { get; set; }
        public string startAgvLoc { get; set; }
        public string endAgvLoc { get; set; }
    }
}
